<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="file" accept="image/*">
    <img src="./u=2968905036,3358167583&fm=253&fmt=auto&app=138&f=JPEG.webp" alt="">
    <button>上传</button>

    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        const dataImg = new FormData()
        const input = document.querySelector('input')
        document.querySelector('button').addEventListener('click', function(e){
            dataImg.append('avatar',input.files[0] )
            // console.log(input.files[0]);
            axios({
                method:'post',
                url:'http://ajax-api.itheima.net/api/file',
                data:dataImg
            }).then(res => document.querySelector('img').src = res.data.data.url)
        })
    </script>
</body>

</html>